home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / MacDOS 1.0.1 / batch files / deldir.bat < prev    next >
Encoding:
DOS Batch File  |  1993-08-05  |  2.4 KB  |  106 lines  |  [TEXT/mDOS]

  1. @echo off
  2. !  deldir.bat    Batch file to delete a folder with all its content
  3. !
  4. !  deldir name
  5. !
  6. !  where 'name' is the folder to be deleted. It can be preceded by a path and a
  7. !  volume ID.
  8. !
  9. !  Copyright © 1993 by Rainbow Hill Pty Ltd. All rights reserved.
  10. !
  11.     set tempfile=TEMP7777
  12.  
  13.     ! ensure that the first parameter is there and that the third one is not
  14.     set doserr=13
  15.     if not "%3 " == " " goto ERR_LBL
  16.     if "%1 " == " " goto ERR_LBL
  17.  
  18.     ! Check whether the second parameter is there. If not, find out where you are
  19.     ! and save the current path in a global variable
  20.     if not "%2 " == " " goto SKIP_HEADER_LBL
  21.         set returnFolder=%WHERE%
  22.         echo Folders being deleted:
  23.     :SKIP_HEADER_LBL
  24.     echo   "%1"
  25.  
  26.     ! change to the folder to be deleted
  27.     cd "%1"
  28.  
  29.     ! Prepare a file with the list of all subfolders.
  30.     onerror DIRERR_LBL
  31.     dir /b/a-f > %tempfile%
  32.     goto DIR_OK_LBL
  33. :DIRERR_LBL
  34.     if not %doserr% == 27 goto ERR_LBL
  35.     ! there are no subfolders, but there could still be files
  36.     goto DELFILES_LBL
  37. :DIR_OK_LBL
  38.  
  39.     ! open the file containing the list of all subfolders
  40.     open %tempfile% fileID
  41.  
  42.     ! save the fileID into a file to make deldir re-entrant
  43.     open/w theFileID id
  44.     write %id% %fileID%
  45.     close %id%
  46.  
  47.     set doserr=0
  48.     onerror X_DELDIR_LOOP_LBL
  49.     repeat DELDIR_LOOP_LBL
  50.  
  51.         ! obtain the folder name
  52.         read %fileID% aDir
  53.         ! remove the double quotes which enclose the names
  54.         decr aDir
  55.         decr -aDir
  56.  
  57.         ! Execute deldir recursively to remove the subfolder.
  58.         ! Pass the 'parent path' as second parameter, so that it will come back
  59.         call deldir "%aDir%" ".."
  60.  
  61.         ! restore the fileID
  62.         open theFileID id
  63.         read %id% fileID
  64.         close %id%
  65.  
  66.         ! now that the fileID is ok, check whether deldir returned an error
  67.         if %doserr% == 0 goto CONTINUE_LOOP_LBL
  68.             close %fileID%
  69.             goto DONE_LBL
  70.  
  71.         :CONTINUE_LOOP_LBL
  72.         :DELDIR_LOOP_LBL
  73.     :X_DELDIR_LOOP_LBL
  74.     if not %doserr% == 3 goto ERR_LBL
  75.  
  76. :DELFILES_LBL
  77.     ! Now that we have removed all the subfolders, we can delete all the files, including
  78.     ! the temporary files which we have created.
  79.     ! Remember that MacDOS does not prompt for confirmation when you want to delete everything
  80.     ! if you are in batch mode.
  81.     onerror ERR_LBL
  82.     del *
  83.  
  84.     
  85.     ! finally, reset the global variables and remove the current folder
  86.     set fileID=
  87.     set id=
  88.     set aDir=
  89.     set doserr=0
  90.     if "%2 " == " " goto TOP_FOLDER_LBL
  91.         cd "%2"
  92.         goto ANY_FOLDER_LBL
  93.     :TOP_FOLDER_LBL
  94.         cd ..
  95.         cd "%returnFolder%"
  96.         set returnFolder=
  97.         set tempfile=
  98.     :ANY_FOLDER_LBL
  99.     rd "%1"
  100.     goto DONE_LBL
  101.  
  102. :ERR_LBL
  103.     show %doserr%
  104.  
  105. :DONE_LBL
  106.